import Cookies from 'js-cookie'

const state = {
  theme: Cookies.get('webColor') || '#1065BF',
  bodyTheme: Cookies.get('bodyTheme') || 'basic0',
  // 判断当前实时出入库弹窗是否已经打开
  isRealTimeOpen: false
}

const mutations = {
  CHANGE_SETTING: (state, { key, value }) => {
    // eslint-disable-next-line no-prototype-builtins
    if (state.hasOwnProperty(key)) {
      state[key] = value
    }
    if (key === 'theme') {
      Cookies.set('webColor', value)
    }
    if (key === 'bodyTheme') {
      Cookies.set('bodyTheme', value)
    }
  }
}

const actions = {
  changeSetting({ commit }, data) {
    commit('CHANGE_SETTING', data)
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
